﻿using System;

namespace HslCommunication.Core.Address
{
	/// <summary>
	/// GE的SRTP协议的地址内容，主要包含一个数据代码信息，还有静态的解析地址的方法<br />
	/// The address content of GE's SRTP protocol mainly includes a data code information, as well as a static method of address resolution
	/// </summary>
	// Token: 0x02000168 RID: 360
	public class GeSRTPAddress : DeviceAddressDataBase
	{
		/// <summary>
		/// 获取或设置等待读取的数据的代码<br />
		/// Get or set the code of the data waiting to be read
		/// </summary>
		// Token: 0x17000619 RID: 1561
		// (get) Token: 0x06001DE8 RID: 7656 RVA: 0x0008E325 File Offset: 0x0008C525
		// (set) Token: 0x06001DE9 RID: 7657 RVA: 0x0008E32D File Offset: 0x0008C52D
		public byte DataCode { get; set; }

		/// <inheritdoc />
		// Token: 0x06001DEA RID: 7658 RVA: 0x0008E338 File Offset: 0x0008C538
		public override void Parse(string address, ushort length)
		{
			OperateResult<GeSRTPAddress> operateResult = GeSRTPAddress.ParseFrom(address, length, false);
			bool isSuccess = operateResult.IsSuccess;
			if (isSuccess)
			{
				base.AddressStart = operateResult.Content.AddressStart;
				base.Length = operateResult.Content.Length;
				this.DataCode = operateResult.Content.DataCode;
			}
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Address.GeSRTPAddress.ParseFrom(System.String,System.UInt16,System.Boolean)" />
		// Token: 0x06001DEB RID: 7659 RVA: 0x0008E394 File Offset: 0x0008C594
		public static OperateResult<GeSRTPAddress> ParseFrom(string address, bool isBit)
		{
			return GeSRTPAddress.ParseFrom(address, 0, isBit);
		}

		/// <summary>
		/// 从GE的地址里，解析出实际的带数据码的 <see cref="T:HslCommunication.Core.Address.GeSRTPAddress" /> 地址信息，起始地址会自动减一，和实际的地址相匹配
		/// </summary>
		/// <param name="address">实际的地址数据</param>
		/// <param name="length">读取的长度信息</param>
		/// <param name="isBit">是否位操作</param>
		/// <returns>是否成功的GE地址对象</returns>
		// Token: 0x06001DEC RID: 7660 RVA: 0x0008E3B0 File Offset: 0x0008C5B0
		public static OperateResult<GeSRTPAddress> ParseFrom(string address, ushort length, bool isBit)
		{
			GeSRTPAddress geSRTPAddress = new GeSRTPAddress();
			try
			{
				geSRTPAddress.Length = length;
				bool flag = address.StartsWith("AI") || address.StartsWith("ai");
				if (flag)
				{
					if (isBit)
					{
						return new OperateResult<GeSRTPAddress>(StringResources.Language.GeSRTPNotSupportBitReadWrite);
					}
					geSRTPAddress.DataCode = 10;
					geSRTPAddress.AddressStart = Convert.ToInt32(address.Substring(2));
				}
				else
				{
					bool flag2 = address.StartsWith("AQ") || address.StartsWith("aq");
					if (flag2)
					{
						if (isBit)
						{
							return new OperateResult<GeSRTPAddress>(StringResources.Language.GeSRTPNotSupportBitReadWrite);
						}
						geSRTPAddress.DataCode = 12;
						geSRTPAddress.AddressStart = Convert.ToInt32(address.Substring(2));
					}
					else
					{
						bool flag3 = address.StartsWith("R") || address.StartsWith("r");
						if (flag3)
						{
							if (isBit)
							{
								return new OperateResult<GeSRTPAddress>(StringResources.Language.GeSRTPNotSupportBitReadWrite);
							}
							geSRTPAddress.DataCode = 8;
							geSRTPAddress.AddressStart = Convert.ToInt32(address.Substring(1));
						}
						else
						{
							bool flag4 = address.StartsWith("SA") || address.StartsWith("sa");
							if (flag4)
							{
								geSRTPAddress.DataCode = (isBit ? 78 : 24);
								geSRTPAddress.AddressStart = Convert.ToInt32(address.Substring(2));
							}
							else
							{
								bool flag5 = address.StartsWith("SB") || address.StartsWith("sb");
								if (flag5)
								{
									geSRTPAddress.DataCode = (isBit ? 80 : 26);
									geSRTPAddress.AddressStart = Convert.ToInt32(address.Substring(2));
								}
								else
								{
									bool flag6 = address.StartsWith("SC") || address.StartsWith("sc");
									if (flag6)
									{
										geSRTPAddress.DataCode = (isBit ? 82 : 28);
										geSRTPAddress.AddressStart = Convert.ToInt32(address.Substring(2));
									}
									else
									{
										bool flag7 = address[0] == 'I' || address[0] == 'i';
										if (flag7)
										{
											geSRTPAddress.DataCode = (isBit ? 70 : 16);
										}
										else
										{
											bool flag8 = address[0] == 'Q' || address[0] == 'q';
											if (flag8)
											{
												geSRTPAddress.DataCode = (isBit ? 72 : 18);
											}
											else
											{
												bool flag9 = address[0] == 'M' || address[0] == 'm';
												if (flag9)
												{
													geSRTPAddress.DataCode = (isBit ? 76 : 22);
												}
												else
												{
													bool flag10 = address[0] == 'T' || address[0] == 't';
													if (flag10)
													{
														geSRTPAddress.DataCode = (isBit ? 74 : 20);
													}
													else
													{
														bool flag11 = address[0] == 'S' || address[0] == 's';
														if (flag11)
														{
															geSRTPAddress.DataCode = (isBit ? 84 : 30);
														}
														else
														{
															bool flag12 = address[0] == 'G' || address[0] == 'g';
															if (!flag12)
															{
																throw new Exception(StringResources.Language.NotSupportedDataType);
															}
															geSRTPAddress.DataCode = (isBit ? 86 : 56);
														}
													}
												}
											}
										}
										geSRTPAddress.AddressStart = Convert.ToInt32(address.Substring(1));
									}
								}
							}
						}
					}
				}
			}
			catch (Exception ex)
			{
				return new OperateResult<GeSRTPAddress>(ex.Message);
			}
			bool flag13 = geSRTPAddress.AddressStart == 0;
			OperateResult<GeSRTPAddress> result;
			if (flag13)
			{
				result = new OperateResult<GeSRTPAddress>(StringResources.Language.GeSRTPAddressCannotBeZero);
			}
			else
			{
				bool flag14 = geSRTPAddress.AddressStart > 0;
				if (flag14)
				{
					GeSRTPAddress geSRTPAddress2 = geSRTPAddress;
					int addressStart = geSRTPAddress2.AddressStart;
					geSRTPAddress2.AddressStart = addressStart - 1;
				}
				result = OperateResult.CreateSuccessResult<GeSRTPAddress>(geSRTPAddress);
			}
			return result;
		}
	}
}
